/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace Oceanside
{
    /// <summary>
    /// Interaction logic for PlaceOrderWindowInstance.xaml
    /// </summary>
    public partial class SplitWindow : PosWindow
    {
        /// <summary>
        /// 
        /// </summary>
        private SplitWindow()
            : base()
        {
            this.InitializeComponent();
            this.Height = PosWindow.MainPosWindow.Height;
            this.Width = PosWindow.MainPosWindow.Width;

            ///Prevent the listview from resizing the columns.
            this.listViewCustTicket.AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler(Functions.Thumb_DragDelta), true);
            this.listViewCustTicket.MouseDoubleClick +=
                new System.Windows.Input.MouseButtonEventHandler(Functions.ListViewCustTicket_MouseDoubleClick);

            this.listViewCustTicket2.AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler(Functions.Thumb_DragDelta), true);
            this.listViewCustTicket2.MouseDoubleClick +=
                new System.Windows.Input.MouseButtonEventHandler(Functions.ListViewCustTicket_MouseDoubleClick);
        }

        static SplitWindow singleton = null;
        static SplitWindow()
        {
            singleton = new SplitWindow();
        }
        public static SplitWindow Singleton
        {
            get
            {
                return singleton;
            }
        }

        private static System.Action prepareForScreenChangeAction;
        public static System.Action PrepareForScreenChangeAction
        {
            get { return prepareForScreenChangeAction; }
            set { prepareForScreenChangeAction = value; }
        }

        private static System.Action prepareForScreenLeaveAction;
        public static System.Action PrepareForScreenLeaveAction
        {
            get { return prepareForScreenLeaveAction; }
            set { prepareForScreenLeaveAction = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public override void PrepareForScreenLeave()
        {
            PrepareForScreenLeaveAction();
        }


        /// <summary>
        /// 
        /// </summary>
        public static Control ExitButton
        {
            get { return singleton.cancelButton; }
        }

        public static FlatButton_52_58 SeatPosition1
        {
            get { return singleton.buttonSeatPosOne; }
        }

        public static FlatButton_52_58 SeatPosition2
        {
            get { return singleton.buttonSeatPosTwo; }
        }
        public static FlatButton_52_58 SeatPosition3
        {
            get { return singleton.buttonSeatPosThree; }
        }

        public static FlatButton_52_58 SeatPosition4
        {
            get { return singleton.buttonSeatPosFour; }
        }

        public static ShineButton_52_58 ScrollSeatLeft
        {
            get { return singleton.buttonScrollSeatLeft; }
        }

        public static ShineButton_52_58 ScrollSeatRight
        {
            get { return singleton.buttonScrollSeatRight; }
        }

        public static Label TableNumberLabel
        {
            get { return singleton.labelTableNumber; }
        }

        public static ListView CustomerTicketListView
        {
            get { return singleton.listViewCustTicket; }
        }


        public static FlatButton_52_58 SeatPosition1_2
        {
            get { return singleton.buttonSeatPosOne2; }
        }

        public static FlatButton_52_58 SeatPosition2_2
        {
            get { return singleton.buttonSeatPosTwo2; }
        }
        public static FlatButton_52_58 SeatPosition3_2
        {
            get { return singleton.buttonSeatPosThree2; }
        }

        public static FlatButton_52_58 SeatPosition4_2
        {
            get { return singleton.buttonSeatPosFour2; }
        }

        public static ShineButton_52_58 ScrollSeatLeft2
        {
            get { return singleton.buttonScrollSeatLeft2; }
        }

        public static ShineButton_52_58 ScrollSeatRight2
        {
            get { return singleton.buttonScrollSeatRight2; }
        }

        public static Label TableNumberLabel2
        {
            get { return singleton.labelTableNumber2; }
        }

        public static ListView CustomerTicketListView2
        {
            get { return singleton.listViewCustTicket2; }
        }

        public static Control DownButton
        {
            get { return singleton.downButton; }
        }

        public static Control DownButton2
        {
            get { return singleton.downButton2; }
        }

        public static Control UpButton
        {
            get { return singleton.upButton; }
        }

        public static Control UpButton2
        {
            get { return singleton.upButton2; }
        }

        public static Button_95_50 NewSeat
        {
            get { return singleton.newSeatButton; }
        }

        public static Button_95_50 NewSeat2
        {
            get { return singleton.newSeatButton2; }
        }

        /// <summary>
        /// 
        /// </summary>
        public override void PrepareForScreenChange()
        {
            PrepareForScreenChangeAction();
        }

        /// <summary>
        /// 
        /// </summary>
        public static void Show()
        {
            SwitchWindowDelegate_NOTHROW(singleton);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        public static void AssignDataContext(object o)
        {
            singleton.DataContext = o;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tc"></param>
        public static void AddInstanceToTabControl(ref TabControl tc)
        {
            tc.Items.Add(singleton);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        public static void SetTabIndex(int index)
        {
            singleton.MyTabIndex = index;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                e.Handled = true;
                UserControl uc = sender as UserControl;
                int index = System.Convert.ToInt32(uc.Tag);
                PosWindow.SplitBoundFunctions[index].Clicked();
            }
            catch (System.Exception ex)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_SPLITBIND_CALL_BOUND_FUNC, ex);
            }
        }
    }
}
